package com.ztf.service;


import com.ztf.serviceThread.ForwardThread;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;

public class Service {
    //绑定每一个连接对象的接受线程和输出流
    public static Map<ForwardThread,ObjectOutputStream> map1 = new HashMap<>();

    //绑定每一个客户与客服的接受线程
    public static Map<ForwardThread,ForwardThread> map2 = new HashMap<>();

    //保存客服得一个循环链表
    public static List<ForwardThread> serverList = new ArrayList<>();
    public static int index = -1;



    //等待队列
    public static Queue<ForwardThread> waitUsers = new LinkedList<>();

    public static void main(String[] args) {
        try {
            ServerSocket ss = new ServerSocket(8080);
            while (true){
                Socket s = ss.accept();
                InputStream is = s.getInputStream();
                ObjectInputStream ois = new ObjectInputStream(is);
                OutputStream os = s.getOutputStream();
                ObjectOutputStream oos  = new ObjectOutputStream(os);
                ForwardThread ft = new ForwardThread(ois);
                ft.start();
                map1.put(ft,oos);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
